package util;

import java.util.regex.Pattern;

/**
 * @Author MJS
 * @Date 2021/12/7 18:09
 * @Description
 */
public class BeautifulNumUtil {
    public static boolean checkBeautifulNum(String num) {
        boolean matches = Pattern.matches("(?:(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){5}|(?:9(?=8)|8(?=7)|7(?=6)|6(?=5)|5(?=4)|4(?=3)|3(?=2)|2(?=1)|1(?=0)){5})\\d", num);
        boolean matches1 = Pattern.matches("^\\d*(\\d)\\1\\1(\\d)\\2\\2\\d*$", num);
        boolean matches2 = Pattern.matches("^(\\d)(\\d)(\\d)\\1\\2\\3$", num);
        boolean matches3 = Pattern.matches("^\\d*(\\d)\\1{2,}\\d*$", num);
        boolean matches4 = Pattern.matches("^(\\d)(\\d)\\2\\1\\2\\2$", num);
        return matches || matches1 || matches2 || matches3 || matches4;
    }

}
